
(function(){

    ADF.domControl.XYComposite = function(parent) {
        ADF.domControl.XYComposite.superclass.constructor.call(this, parent);
    };

    COM.util.defineClass(ADF.domControl.XYComposite, ADF.domControl.Composite, {
        getLabel: function(){
            return "XYComposite";
        },
        appendDomChild: function(child) {
            this.getDomElement().appendChild(child);
        },
        removeDomChild: function(child) {
            this.getDomElement().removeChild(child);
        },
        _getDomElement: function(model) {
            var composite = COM.util.HTMLUtil.createELement('<div class="adf_xy_composite"></div>');
            this.domElement = composite[0];
            if(model.isGrid) {
                this.createGridLine(this.domElement);
            }
            return this.domElement;
        },
        createGridLine: function(dom) {
            var svg = COM.util.HTMLUtil.createELement('<svg xmlns="http://www.w3.org/2000/svg" id="main" version="1.1" style="position:absolute" width="100%" height="100%"></svg>');
            for(var i=1; i< 200; i++) {
                var x = i*15 - 0.5;
                var hline = COM.util.HTMLUtil.createELement('<line x1='+x+' y1="0" x2='+x+' y2="100%" style="stroke:rgba(120,120,120,0.3);stroke-width:1;stroke-dasharray:1;"/>');
                var vline = COM.util.HTMLUtil.createELement('<line x1="0" y1='+x+' x2="100%" y2='+x+' style="stroke:rgba(120,120,120,0.3);stroke-width:1;stroke-dasharray:1;"/>');
                svg.append(hline);
                svg.append(vline);
            }
            svg.html(svg.html());
            dom.appendChild(svg[0]);
        },
        layoutChild : function(child){
            var childDom = child.getDomElement();
            var layoutData = child.getLayoutData();
            if(layoutData){
                var css = {"display":"block", "position":"absolute", "left":layoutData.x, "top":layoutData.y};
                if(layoutData.width >= 0) {
                    css.width = layoutData.width;
                }
                if(layoutData.height >= 0) {
                    css.height = layoutData.height;
                }
                $(childDom).css(css);
            }
        }
    });
})();